Global Search To Create Attribute

I have been using the Global Search Utility, which has been very helpful to search many terms/modules at the same time. However, I need to show which term was found in its own attribute column.

I have been trying to write a DXL script to add an object attribute that shows which term was found in the search. Below is some pseudo code that explains what I am trying to do. I have tried it from a few different angles but still doesn't do what I need. Any guidance would be much appreciated.
 

string SearchTerm[] = {"Term1", "Term2", "Term3", "etc."}
 
For all obj in module
{
//Search all objects to see if it contains a term.
If (obj."Object Text" || obj."Object Heading" contains SearchTerm[i] )
{
//set the attribute to the term it found.
Set obj."Found Term" = SearchTerm[i]
}
}

SystemAdmin - Fri Jul 27 13:20:58 EDT 2012

Re: Global Search To Create Attribute
llandale - Fri Jul 27 13:52:24 EDT 2012

string SearchTerm[] = {"Term1", "Term2", "Term3", "etc."}
 
Buffer bufResults = create()
For all obj in module
{
   //Search all objects to see if it contains a term.
   Comma = ", "
   bufResults = ""
   for (i=0; i<sizeof(SearchTerm); i++)
   {  if (obj."Object Text" || obj."Object Heading" contains SearchTerm[i] )
      {  bufResults += Comma
         bufReSults += SearchTerm[i]
         Comma       = ", "  // Get ready for next found term, if any
      }
   //set the attribute to the term it found.
   }
   obj."Found Term" = tempStringOf(bufResults)
}
delete(bufResults)


if "Found Term" is an enumerated attr then change .

-Louie

Re: Global Search To Create Attribute
SystemAdmin - Fri Jul 27 20:58:56 EDT 2012

llandale - Fri Jul 27 13:52:24 EDT 2012

string SearchTerm[] = {"Term1", "Term2", "Term3", "etc."}
 
Buffer bufResults = create()
For all obj in module
{
   //Search all objects to see if it contains a term.
   Comma = ", "
   bufResults = ""
   for (i=0; i<sizeof(SearchTerm); i++)
   {  if (obj."Object Text" || obj."Object Heading" contains SearchTerm[i] )
      {  bufResults += Comma
         bufReSults += SearchTerm[i]
         Comma       = ", "  // Get ready for next found term, if any
      }
   //set the attribute to the term it found.
   }
   obj."Found Term" = tempStringOf(bufResults)
}
delete(bufResults)


if "Found Term" is an enumerated attr then change .

-Louie

Louie,

Thank you for the quick reply. When I run the script I still get the error "incorrect arguments for function (contains)". I am not sure if "contains" can be used here?
Thanks

Re: Global Search To Create Attribute
llandale - Sat Jul 28 14:51:22 EDT 2012

SystemAdmin - Fri Jul 27 20:58:56 EDT 2012
Louie,

Thank you for the quick reply. When I run the script I still get the error "incorrect arguments for function (contains)". I am not sure if "contains" can be used here?
Thanks

that's your part, it is psuedo code.

Re: Global Search To Create Attribute
SystemAdmin - Sat Jul 28 20:39:28 EDT 2012

llandale - Sat Jul 28 14:51:22 EDT 2012
that's your part, it is psuedo code.

Louis,

Thank you very much for your help. I completed the code if anyone else is interested. I was using "FindPlainText" incorrectly before and i ended up going down the wrong path trying "contains". Let me know if anyone sees a way i can improve the script, i am sure it can be better. For now it does exactly what I need though.
 

pragma encoding, "UTF-8"
 
string SearchTerm[] = {"Term1", "Term2", "Term3", "etc."}
Module m = current 
Object o = current
string objectHeading, objectText, objectBoth
Buffer bufResults = create()
 
for o in m do
{
    //search both object text and headings
        objectText = richText o."Object Text"
        objectHeading = richText o."Object Heading" 
        objectBoth = objectHeading " " objectText 
        
        int offset = null
        int length = null
        bool matchCase = false
        bool reverse = false
           
   Comma = ", "
   bufResults = ""
  
  //loop through all terms
   for (i=0; i<sizeof(SearchTerm); i++)
   {  
  //Search the text.
   if (findPlainText (objectBoth, SearchTerm[i], offset, length, matchCase, reverse))
   {
                bufResults += SearchTerm[i]
                bufResults += Comma
                bufResults += "\n"
                o."Found Term" = tempStringOf(bufResults)    //set the attribute to the term(s) found.
   
   continue // Search remaining terms
   }
        else
        {
        null
         }
}
}
delete(bufResults)

Re: Global Search To Create Attribute
SystemAdmin - Tue Jan 15 15:32:28 EST 2013

I am trying to extend my original code with so that other users can enter their specifc terms in a dialogue box rather than through the DXL text file.

Basically i am looking for a loop that can parse a string into an array. Then the array will be looped through by the search function for all terms. As it is currently it can only search one term at a time.

Below is my code. Commented out in green is some pseudo code that I am not sure what to do next.

Any guidance would be much appreciated.
 

pragma encoding, "UTF-8"
 
DB searchDB = create ("Search Utility", styleStandard)
DBE InfoTextDBE = text(searchDB, "Instructions", "Enter Search terms. Enter attribute name for column.", 200, 50, true)
DBE SearchTextDBE = text(searchDB, "Search terms", "", 200, 50, false)
Module m = current 
Object o = current
 
    
void searchFunction (DB win) 
        {
                Buffer bufResults = create()
                string objectHeading, objectText, objectBoth
                string searchTerms[] = get SearchTextDBE
                
               /**
                //for the entire string entered in the text box 
                for (i=0; i<sizeof(searchTerms); i++) 
                {
                   parse out each term separated by a comma 
                   save each term into an array 
                   bufResults += Terms[i]
                   then continue until the end of string
                }
                **/
 
                for o in m do
                {
                        //search both object text and headings
                        objectText = richText o."Object Text"
                        objectHeading = richText o."Object Heading" 
                        objectBoth = objectHeading " " objectText 
        
                        int offset = null
                        int length = null
                        bool matchCase = false
                        bool reverse = false
                        string Comma  
                        Comma = ", "
                        bufResults = ""
  
                        //loop through all terms in the array
                        for (i=0; i<sizeof(searchTerms); i++)
                        {
                         //Search all objects.
                         if (findPlainText (objectBoth, searchTerms[i], offset, length, matchCase, reverse))
                                {
                                bufResults += searchTerms[i]
                                bufResults += Comma
                                bufResults += "\n"
                                o."SearchTerm" = stringOf(bufResults)    //set the attribute to the term(s) found.
                        
                                continue // Search remaining terms
                                }
                                else
                                {
                                        null
                                }
                  }
                }
        }    
 
void closeWindow (DB searchDB) 
{
hide (searchDB)
}
apply (searchDB, "Search Terms", searchFunction)
close (searchDB, true, closeWindow)
show searchDB

Re: Global Search To Create Attribute
SystemAdmin - Tue Jan 15 15:32:50 EST 2013

Looking for a loop to parse a string separated by commas into an array.